package org.test;


import java.sql.*;
import java.util.*;
import java.util.concurrent.*;

public class ClickHouseThreadTest1 {
    private static String sql1 = "select T_DATE,PONT_RAT,BASI_CODE from MID_L2_BASI WHERE T_DATE>=#STARTDATE AND T_DATE<=#ENDDATE AND (BASI_CODE='119655' OR BASI_CODE='119525')";
    //private static String sql2 = "select T_DATE,PONT_RAT from MID_L2_BASI WHERE T_DATE>=#STARTDATE AND T_DATE<=#ENDDATE AND BASI_CODE in('119525')";
    private static String sql3 = "select T_DATE,UNIT_NVAL_RATE,IS_TRD_DT,SECU_ID from MID_L2_PRD_TRD_ASSM WHERE T_DATE>=#STARTDATE AND T_DATE<=#ENDDATE AND SECU_ID in(#CODE)";
    private static String code11 = "'000001.OTC','000005.OTC','000007.OTC','000010.OTC','000015.OTC','000021.OTC','000024.OTC','000028.OTC','000029.OTC','000030.OTC','000031.OTC','000033.OTC','000037.OTC','000038.OTC','000039.OTC','000042.OTC','000046.OTC','000047.OTC','000051.OTC','000056.OTC','000060.OTC','000062.OTC','000063.OTC','000064.OTC','000065.OTC','000068.OTC','000071.OTC','000073.OTC','000074.OTC','000078.OTC','000079.OTC','000083.OTC','000086.OTC','000088.OTC','000092.OTC','000093.OTC','000103.OTC','000107.OTC','000109.OTC','000111.OTC','000112.OTC','000113.OTC','000116.OTC','000117.OTC','000118.OTC','000120.OTC','000121.OTC','000124.OTC','000125.OTC','000126.OTC','000128.OTC','000129.OTC','000130.OTC','000131.OTC','000133.OTC','000135.OTC','000139.OTC','000143.OTC','000148.OTC','000149.OTC','000152.OTC','000153.OTC','000167.OTC','000170.OTC','000171.OTC','000174.OTC','000176.OTC','000180.OTC','000184.OTC','000185.OTC','000188.OTC','000189.OTC','000192.OTC','000194.OTC','000199.OTC','000202.OTC','000206.OTC','000207.OTC','000211.OTC','000212.OTC','000216.OTC','000218.OTC','000220.OTC','000225.OTC','000239.OTC','000248.OTC','000251.OTC','000252.OTC','000255.OTC','000260.OTC','000265.OTC','000266.OTC','000270.OTC','000275.OTC','000280.OTC','000281.OTC','000284.OTC','000286.OTC','000288.OTC','000289.OTC','000292.OTC','000293.OTC','000295.OTC','000297.OTC','000298.OTC','000300.OTC','000301.OTC','000303.OTC','000304.OTC','000305.OTC','000308.OTC','000309.OTC','000311.OTC','000312.OTC','000313.OTC','000317.OTC','000318.OTC','000319.OTC','000320.OTC','000322.OTC','000326.OTC','000327.OTC','000328.OTC','000331.OTC','000335.OTC','000336.OTC','000345.OTC','000348.OTC','000349.OTC','000354.OTC','000355.OTC','000357.OTC','000359.OTC','000361.OTC','000363.OTC','000368.OTC','000371.OTC','000372.OTC','000376.OTC','000377.OTC','000381.OTC','000386.OTC','000390.OTC','000392.OTC','000394.OTC','000395.OTC','000398.OTC','000401.OTC','000402.OTC','000403.OTC','000407.OTC','000408.OTC','000409.OTC','000412.OTC','000416.OTC','000417.OTC','000418.OTC','000419.OTC','000420.OTC','000421.OTC','000426.OTC','000429.OTC','000430.OTC','000434.OTC','000435.OTC','000436.OTC','000438.OTC','000439.OTC','000452.OTC','000455.OTC','000457.OTC','000458.OTC','000462.OTC','000467.OTC','000469.OTC','000471.OTC','000475.OTC','000476.OTC','000478.OTC','000479.OTC','000480.OTC','000484.OTC','000485.OTC','000489.OTC','000493.OTC','000501.OTC','000502.OTC','000507.OTC','00050A.OTC','000511.OTC','000513.OTC','000516.OTC','000520.OTC','000523.OTC','000533.OTC','000534.OTC','000536.OTC','000538.OTC','000539.OTC','000543.OTC','000548.OTC','000552.OTC','000556.OTC','000557.OTC','000559.OTC','000561.OTC','000563.OTC','000566.OTC','000574.OTC','000575.OTC','000580.OTC','000583.OTC','000584.OTC','000586.OTC','000587.OTC','000590.OTC','000591.OTC','000595.OTC','000596.OTC','000603.OTC','000604.OTC','000605.OTC','000606.OTC','000609.OTC','000613.OTC','000616.OTC','000617.OTC','000618.OTC','000623.OTC','000625.OTC','000626.OTC','000627.OTC','00062A.OTC','000638.OTC','00063A.OTC','000640.OTC','000642.OTC','000643.OTC','000644.OTC','000645.OTC','000654.OTC','000656.OTC','000662.OTC','000663.OTC','000668.OTC','000671.OTC','000672.OTC','000676.OTC','000677.OTC','000679.OTC','000681.OTC','000686.OTC','000690.OTC','000695.OTC','000699.OTC','000700.OTC','000708.OTC','000710.OTC','000711.OTC','000712.OTC','000716.OTC','000717.OTC','000719.OTC','000720.OTC','000721.OTC','000723.OTC','000724.OTC','000725.OTC','000726.OTC','000730.OTC','000735.OTC','000739.OTC','000741.OTC','000743.OTC','000744.OTC','000747.OTC','000749.OTC','000750.OTC','000752.OTC','000753.OTC','000757.OTC','000758.OTC','000762.OTC','000765.OTC','000767.OTC','000770.OTC','000771.OTC','000773.OTC','000775.OTC','000780.OTC','000781.OTC','000783.OTC','000785.OTC','000787.OTC','000789.OTC','000793.OTC','000794.OTC','000798.OTC','000799.OTC','000800.OTC','000804.OTC','000805.OTC','000809.OTC','000814.OTC','000816.OTC','000818.OTC','000819.OTC','000823.OTC','000825.OTC','000827.OTC','000828.OTC','000829.OTC','000830.OTC','000831.OTC','000832.OTC','000837.OTC','000841.OTC','000843.OTC','000846.OTC','000850.OTC','000855.OTC','000863.OTC','000866.OTC','000867.OTC','000868.OTC','000869.OTC','000873.OTC','000878.OTC','000882.OTC','000886.OTC','000887.OTC','000891.OTC','000893.OTC','000895.OTC','000896.OTC','000904.OTC','000906.OTC','000908.OTC','000912.OTC','000913.OTC','000917.OTC','00091A.OTC','00091B.OTC','000922.OTC','000926.OTC','000927.OTC','000928.OTC','000930.OTC','000931.OTC','000934.OTC','000936.OTC','000940.OTC','000945.OTC','000952.OTC','000954.OTC','000959.OTC','000963.OTC','000967.OTC','000968.OTC','000972.OTC','000976.OTC','000977.OTC','000980.OTC','000981.OTC','000982.OTC','000986.OTC','000989.OTC','000990.OTC','000991.OTC','000994.OTC','000995.OTC','000997.OTC','001000.OTC','001004.OTC','001007.OTC','001009.OTC','001013.OTC','001015.OTC','001017.OTC','001018.OTC','001021.OTC','001023.OTC','001027.OTC','001029.OTC','001030.OTC','001031.OTC','001035.OTC','001036.OTC','001040.OTC','001042.OTC','001044.OTC','001045.OTC','001046.OTC','001048.OTC','001051.OTC','001053.OTC','001054.OTC','001055.OTC','001058.OTC','001059.OTC','001063.OTC','001067.OTC','001068.OTC','001072.OTC','001077.OTC','001086.OTC','001088.OTC','001092.OTC','001093.OTC','001095.OTC','001101.OTC','001105.OTC','001106.OTC','001110.OTC','001113.OTC','001115.OTC','001121.OTC','001123.OTC','001124.OTC','001128.OTC','001133.OTC','001135.OTC','001137.OTC','001138.OTC','001141.OTC','001142.OTC','001147.OTC','001150.OTC','001152.OTC','001156.OTC','001158.OTC','001160.OTC','001161.OTC','001164.OTC','001165.OTC','001166.OTC','001173.OTC','001174.OTC','001178.OTC','001179.OTC','001181.OTC','001182.OTC','001183.OTC','001188.OTC','001189.OTC','001192.OTC','001196.OTC','001197.OTC','001198.OTC','001199.OTC','001200.OTC','001202.OTC','001204.OTC','001205.OTC','001207.OTC','001209.OTC','001210.OTC','001214.OTC','001216.OTC','001218.OTC','001219.OTC','001222.OTC','001223.OTC','001224.OTC','001228.OTC','001231.OTC','001236.OTC','001237.OTC','001239.OTC','001240.OTC','001241.OTC','001242.OTC','001243.OTC','001245.OTC','001246.OTC','001247.OTC','001250.OTC','001253.OTC','001254.OTC','001255.OTC','001257.OTC','001258.OTC','001259.OTC','001260.OTC','001262.OTC','001264.OTC','001268.OTC','001272.OTC','001273.OTC','001277.OTC','001278.OTC','001279.OTC','001281.OTC','001282.OTC','001287.OTC','001291.OTC','001296.OTC','001297.OTC','001303.OTC','001304.OTC','001309.OTC','001310.OTC','001312.OTC','001313.OTC','001314.OTC','001318.OTC','001321.OTC','001322.OTC','001323.OTC','001324.OTC','001326.OTC','001327.OTC','001328.OTC','001331.OTC','001335.OTC','001336.OTC','001340.OTC','001341.OTC','001344.OTC','001345.OTC','001347.OTC','001349.OTC','001354.OTC','001358.OTC','001359.OTC','001362.OTC','001363.OTC','001376.OTC','001377.OTC','001378.OTC','001380.OTC','001381.OTC','001386.OTC','001390.OTC','001395.OTC','001399.OTC','001400.OTC','001401.OTC','001403.OTC','001405.OTC','001406.OTC','001410.OTC','001411.OTC','001415.OTC','001418.OTC','001420.OTC','001423.OTC','001424.OTC','001425.OTC','001428.OTC','001429.OTC','001430.OTC','001433.OTC','001437.OTC','001438.OTC','001441.OTC','001442.OTC','001444.OTC','001445.OTC','001446.OTC','001447.OTC','001448.OTC','001451.OTC','001455.OTC','001456.OTC','001457.OTC','001460.OTC','001464.OTC','001465.OTC','001466.OTC','001469.OTC','001474.OTC','001478.OTC','001479.OTC','001483.OTC','001484.OTC','001487.OTC','001488.OTC','001490.OTC','001492.OTC','001497.OTC','001500.OTC','001501.OTC','001504.OTC','001505.OTC','001507.OTC','001510.OTC','001513.OTC','001515.OTC','001519.OTC','001522.OTC','001523.OTC','001527.OTC','001528.OTC','001531.OTC','001532.OTC','001534.OTC','001536.OTC','001537.OTC','001538.OTC','001541.OTC','001545.OTC','001546.OTC','001547.OTC','001550.OTC','001555.OTC','001558.OTC','001559.OTC','001563.OTC','001564.OTC','001565.OTC','001567.OTC','001569.OTC','001573.OTC','001577.OTC','001578.OTC','001579.OTC','001582.OTC','001586.OTC','001587.OTC','001591.OTC','001596.OTC','001602.OTC','001607.OTC','001610.OTC','001611.OTC','001615.OTC','001616.OTC','001618.OTC','001621.OTC','001624.OTC','001625.OTC','001629.OTC','001631.OTC','001632.OTC','001633.OTC','001634.OTC','001635.OTC','001639.OTC','001640.OTC','001643.OTC','001644.OTC','001647.OTC','001648.OTC','001651.OTC','001652.OTC','001653.OTC','001656.OTC','001657.OTC','001661.OTC','001665.OTC','001666.OTC','001670.OTC','001671.OTC','001674.OTC','001675.OTC','001677.OTC','001679.OTC','001688.OTC','001692.OTC','001693.OTC','001698.OTC','001700.OTC','001701.OTC','001702.OTC','001706.OTC','001708.OTC','001710.OTC','001714.OTC','001715.OTC','001721.OTC','001723.OTC','001724.OTC','001725.OTC','001728.OTC','001729.OTC','001732.OTC','001733.OTC','001734.OTC','001737.OTC','001738.OTC','001739.OTC','001742.OTC','001751.OTC','001752.OTC','001755.OTC','001756.OTC','001758.OTC','001760.OTC','001764.OTC','001765.OTC','001767.OTC','001779.OTC','001783.OTC','001787.OTC','001788.OTC','001791.OTC','001792.OTC','001794.OTC','001795.OTC','001796.OTC','001797.OTC','001800.OTC','001802.OTC','001806.OTC','001808.OTC','001809.OTC','001811.OTC','001813.OTC','001815.OTC','001817.OTC','001818.OTC','001819.OTC','001823.OTC','001827.OTC','001832.OTC','001836.OTC','001837.OTC','001839.OTC','001841.OTC','001846.OTC','001852.OTC','001857.OTC','001858.OTC','001861.OTC','001862.OTC','001866.OTC','001867.OTC','001868.OTC','001870.OTC','001871.OTC','001872.OTC','001874.OTC','001875.OTC','001876.OTC','001877.OTC','001878.OTC','001880.OTC','001885.OTC','001888.OTC','001889.OTC','001893.OTC','001894.OTC','001895.OTC','001897.OTC','001899.OTC','001901.OTC','001902.OTC','001903.OTC','001907.OTC','001910.OTC','001911.OTC','001915.OTC','001916.OTC','001920.OTC','001921.OTC','001924.OTC','001925.OTC','001926.OTC','001928.OTC','001929.OTC','001932.OTC','001933.OTC','001934.OTC','001936.OTC','001937.OTC','001938.OTC','001939.OTC','001940.OTC','001943.OTC','001945.OTC','001947.OTC','001948.OTC','001951.OTC','001952.OTC','001956.OTC','001959.OTC','001960.OTC','001961.OTC','001966.OTC','001969.OTC','001970.OTC','001974.OTC','001975.OTC','001976.OTC','001984.OTC','001988.OTC','001989.OTC','001993.OTC','001997.OTC','001998.OTC','002006.OTC','002007.OTC','002008.OTC','002011.OTC','002015.OTC','002016.OTC','002020.OTC','002024.OTC','002025.OTC','002031.OTC','002033.OTC','002034.OTC','002039.OTC','002042.OTC','002045.OTC','002048.OTC','002051.OTC','002052.OTC','002057.OTC','002060.OTC','002061.OTC','002062.OTC','002065.OTC','002066.OTC','002068.OTC','002070.OTC','002071.OTC','002073.OTC','002074.OTC','002075.OTC','002077.OTC','002079.OTC','002081.OTC','002082.OTC','002083.OTC','002084.OTC','002085.OTC','002088.OTC','002089.OTC','002092.OTC','002093.OTC','002097.OTC','002098.OTC','002101.OTC','002106.OTC','002110.OTC','002112.OTC','002113.OTC','002114.OTC','002115.OTC','002123.OTC','002124.OTC','002126.OTC','002129.OTC','002132.OTC','002133.OTC','002138.OTC','002141.OTC','002142.OTC','002146.OTC','002147.OTC','002149.OTC','002150.OTC','002156.OTC','002160.OTC','002164.OTC','002165.OTC','002166.OTC','002169.OTC','002173.OTC','002174.OTC','002177.OTC','002178.OTC','002179.OTC','002180.OTC','002181.OTC','002182.OTC','002183.OTC','002184.OTC','002186.OTC','002187.OTC','002188.OTC','002189.OTC','002191.OTC','002192.OTC','002195.OTC','002196.OTC','002197.OTC','002202.OTC','002203.OTC','002207.OTC','002208.OTC','002212.OTC','002216.OTC','002217.OTC','002218.OTC','002220.OTC','002221.OTC','002226.OTC','002230.OTC','002232.OTC','002235.OTC','002244.OTC','002249.OTC','002252.OTC','002255.OTC','002256.OTC','002258.OTC','002260.OTC','002262.OTC','002266.OTC','002267.OTC','002269.OTC','002270.OTC','002271.OTC','002272.OTC','002275.OTC','002276.OTC','002280.OTC','002284.OTC','002285.OTC','002289.OTC','002290.OTC','002292.OTC','002293.OTC','002294.OTC','002295.OTC','002299.OTC','002300.OTC','002301.OTC','002302.OTC','002307.OTC','002310.OTC','002311.OTC','002313.OTC','002316.OTC','002325.OTC','002330.OTC','002333.OTC','002334.OTC','002336.OTC','002338.OTC','002339.OTC','002345.OTC','002348.OTC','002350.OTC','002351.OTC','002357.OTC','002360.OTC','002361.OTC','002362.OTC','002365.OTC','002366.OTC','002367.OTC','002370.OTC','002371.OTC','002372.OTC','002374.OTC','002375.OTC','002376.OTC','002378.OTC','002383.OTC','002384.OTC','002388.OTC','002389.OTC','002390.OTC','002393.OTC','002397.OTC','002398.OTC','002399.OTC','002404.OTC','002405.OTC','002407.OTC','002408.OTC','002409.OTC','002411.OTC','002413.OTC','002414.OTC','002417.OTC','002418.OTC','002419.OTC','002422.OTC','002426.OTC','002427.OTC','002431.OTC','002435.OTC','002436.OTC','002440.OTC','002445.OTC','002451.OTC','002453.OTC','002454.OTC','002458.OTC','002459.OTC','002463.OTC','002468.OTC','002471.OTC','002472.OTC','002476.OTC','002477.OTC','002479.OTC','002481.OTC','002482.OTC','002485.OTC','002486.OTC','002488.OTC','002490.OTC','002492.OTC','002494.OTC'";
    private static String[] codes = new HashSet<>(Arrays.asList(code11.trim().split(","))).toArray(new String[0]);
    private static String address = "jdbc:clickhouse://192.168.0.171:8123/mid_test";

    public static void main(String[] args) throws Exception {

        int codeNum = 1; //每个并发code个数
        int freq = 20;   //并发个数
        long t1 = System.currentTimeMillis();
        System.out.println("----------------------------------- t1 开始:"+t1);

        ExecutorService executorService = new ThreadPoolExecutor(freq, freq, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(freq), new ThreadPoolExecutor.AbortPolicy());
        CountDownLatch fetchSourceLatch = new CountDownLatch(freq);

        for (int i = 1; i <= freq; i++) {
            executorService.submit(() -> new ClickHouseThreadTest1().calc(codeNum, fetchSourceLatch));
        }

        long t222 = System.currentTimeMillis();
        System.out.println("----------------------------------- t222-t1 创建线程耗时:"+(t222-t1));

        executorService.shutdown();
        fetchSourceLatch.await();

        long t2 = System.currentTimeMillis();
        System.out.println("----------------------------------- t2-t1 总耗时:"+(t2-t1));
    }

    public void calc(int codeNum, CountDownLatch latch) {
        try {
            long t0 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t0:"+t0);
            DruidTest druidTest = new DruidTest();
            Connection connection = druidTest.getConnection();
            PreparedStatement ps = null;
            ResultSet resultSet = null;
            long t1_1 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t1-t0 连接耗时:"+(t1_1-t0));

            Random rand = new Random();
            String startDate = JodaUtils.getPlusDays("20180303", -rand.nextInt(184));
            String endDate = JodaUtils.getPlusDays("20200302", rand.nextInt(184));

            String sql11 = sql1.replaceAll("#STARTDATE", startDate).replaceAll("#ENDDATE", endDate);
            //String sql22 = sql2.replaceAll("#STARTDATE", startDate).replaceAll("#ENDDATE", endDate);

            long t1 = System.currentTimeMillis();
            ps = connection.prepareStatement(sql11);
            long t11 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t11-t1 sql11 prepareStatement耗时:"+(t11-t1));
            resultSet = ps.executeQuery();
            long t12 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t12-t11 sql11 executeQuery耗时:"+(t12-t11));
            Map<String, TreeMap<String, String[]>> map1 = new HashMap<>();
            while (resultSet.next()) {
                oneRowToMap(resultSet, map1, "BASI_CODE");
            }
            long t2 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t2-t1 读MID_L2_BASI总耗时:"+(t2-t1));

//            ps = connection.prepareStatement(sql22);
//            resultSet = ps.executeQuery();
//            TreeMap<String, String[]> map2 = new TreeMap<>();
//            while (resultSet.next()) {
//                oneRowToMap(resultSet, map2);
//            }
//            long t3 = System.currentTimeMillis();
//            System.out.println("----------------------------------- calc t3-t2 读MID_L2_BASI(119525)耗时:"+(t3-t2));

            String codeStr = "";
            int j = 0;
            while(true) {
                String code = codes[rand.nextInt(codes.length)];
                if(!codeStr.contains(code)) {
                    codeStr = codeStr.isEmpty()? code : codeStr + "," + code;
                    if(++j>=codeNum) break;
                }
            }

            String sql33 = sql3.replaceAll("#STARTDATE", startDate).replaceAll("#ENDDATE", endDate).replaceAll("#CODE", codeStr);

            ps = connection.prepareStatement(sql33);
            long t13 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t13-t2 sql33 prepareStatement耗时:"+(t13-t2));
            resultSet = ps.executeQuery();
            long t14 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t14-t13 sql33 executeQuery耗时:"+(t14-t13));
            Map<String, TreeMap<String, String[]>> map3 = new HashMap<>();
            while (resultSet.next()) {
                oneRowToMap(resultSet, map3, "SECU_ID");
            }
            long t4 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t4-t2 读MID_L2_PRD_TRD_ASSM耗时:"+(t4-t2));

            int i = 0;
            int days = 0;
            List<Double> list2 = new ArrayList<>();
            List<Double> list3 = new ArrayList<>();
            List<String> list4 = new ArrayList<>();
            for(TreeMap<String, String[]> map : map3.values()) {
                i++;
                int oneAcc = 0;  //日期连续标记为1的次数
                double yield1 = 0;
                double yield2 = 0;
                double yield3 = 0;
                List<Double> list1 = new ArrayList<>();
                for (String key : map.keySet()) {
                    if ("0".equals((String)map.get(key)[2])) {
                        oneAcc = 0;
                        yield1 = (1 + yield1) * (1 + Double.valueOf(map.get(key)[1])) - 1;
                        if(i == 1) {
                            yield2 = (1 + yield2) * (1 + Double.valueOf(map1.get("119655").get(key)[1])) - 1;
                            yield3 = (1 + yield3) * (1 + Double.valueOf(map1.get("119525").get(key)[1])) - 1;
                        }
                    }else if ("1".equals((String)map.get(key)[2])) {
                        oneAcc += 1;
                        list1.add(oneAcc==1? ((1 + yield1) * (1 + Double.valueOf(map.get(key)[1])) - 1): Double.valueOf(map.get(key)[1]));
                        yield1 = 0;
                        if(i == 1) {
                            list2.add(oneAcc == 1 ? ((1 + yield2) * (1 + Double.valueOf(map1.get("119655").get(key)[1])) - 1) : Double.valueOf(map1.get("119655").get(key)[1]));
                            list3.add(oneAcc == 1 ? ((1 + yield3) * (1 + Double.valueOf(map1.get("119525").get(key)[1])) - 1) : Double.valueOf(map1.get("119525").get(key)[1]));
                            yield2 = 0;
                            yield3 = 0;
                            list4.add(key);
                        }
                    }
                }

                //求出年化时的天数
                if(i == 1) {
                    days = map.size();
                    for(String key : map.descendingKeySet()) {
                        if ("1".equals((String)map.get(key)[2])) {
                            break;
                        }else if ("0".equals((String)map.get(key)[2])) {
                            days -= 1;
                        }
                    }
                }

                double sharpe = IndexFuncUtil.sharpe(list1, list2, false, "D");
                double IntervalRat = IndexFuncUtil.IntervalRat(list1, days, true, "D");
                double std = IndexFuncUtil.std(list1, false, "D");
                double sortino = IndexFuncUtil.sortino(list1, list2, Double.valueOf(0), false, "D");
                double jenson = IndexFuncUtil.jenson(list1, list2, list3, false, "D");
//                double treynor = IndexFuncUtil.treynor(list1, list2, list3, false, "D");
//                double md = IndexFuncUtil.md(list1, list4);
//                System.out.println("sharpe:"+sharpe+";sortino:"+sortino+";jenson:"+jenson);
            }
            long t5 = System.currentTimeMillis();
            System.out.println("----------------------------------- calc t5-t4 计算耗时:"+(t5-t4));

            if (resultSet != null) resultSet.close();
            if (ps != null) ps.close();
            if (connection != null) connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            latch.countDown();
        }
    }

    public void oneRowToMap(ResultSet rs, TreeMap<String, String[]> map) throws Exception {
        ResultSetMetaData rd = rs.getMetaData();
        String[] object = new String[rd.getColumnCount()];

        for (int i = 0; i < rd.getColumnCount(); i++) {
            object[i] = rs.getString(i+1);
        }

        map.put(rs.getString("T_DATE"), object);
    }

    public void oneRowToMap(ResultSet rs, Map<String, TreeMap<String, String[]>> map, String codeName) throws Exception {
        ResultSetMetaData rd = rs.getMetaData();
        String[] object = new String[rd.getColumnCount()];

        for (int i = 0; i < rd.getColumnCount(); i++) {
            object[i] = rs.getString(i+1);
        }

        String code = rs.getString(codeName);
        TreeMap<String, String[]> tmap = map.getOrDefault(code, new TreeMap<>());
        tmap.put(rs.getString("T_DATE"), object);
        map.put(code, tmap);
    }

}
